using System.Drawing;
using GTA;
using NativeUI;

namespace CustomPeds.Menus;

public class DressingRoomAdvancedMenu : Script
{
    public static UIMenu menu = new UIMenu("", TextSetting.dra_Menu, new Point(0, -107));
    private static bool inited;

    public DressingRoomAdvancedMenu()
    {
        if (!inited)
        {
            Main.pool.Add(menu);
            menu.OnMenuClose += OnMenuClose;
            menu.OnItemSelect += OnItemSelect;
            inited = true;
        }
    }

    public static void InitAdvancedMenu()
    {
        menu.Clear();
        menu.SetBannerType(new UIResRectangle());
        menu.AddItem(new UIMenuItem(TextSetting.dra_MenuItem_HeadBlend, TextSetting.dr_MenuItem_AdvancedSettings_dct));
        menu.AddItem(new UIMenuItem(TextSetting.dra_MenuItem_FaceFeature, TextSetting.dr_MenuItem_AdvancedSettings_dct));
        menu.AddItem(new UIMenuItem(TextSetting.dra_MenuItem_HeadOverlay, TextSetting.dr_MenuItem_AdvancedSettings_dct));
        menu.AddItem(new UIMenuItem(TextSetting.dra_MenuItem_SpeechSettings, TextSetting.dra_MenuItem_SpeechSettings_dct));
        menu.BindMenuToItem(HeadBlendSubMenu.menu, menu.MenuItems[0]);
        menu.BindMenuToItem(FaceFeatureSubMenu.menu, menu.MenuItems[1]);
        menu.BindMenuToItem(HeadOverlayMenu.menu, menu.MenuItems[2]);
        menu.BindMenuToItem(SpeechMenu.menu, menu.MenuItems[3]);
        menu.RefreshIndex();
        CheckCanUseMenuItem();
        menu.Visible = true;
    }

    public static void CheckCanUseMenuItem()
    {
        bool enableAfterHeadBlend = false;
        if (DressingScript.Dressing == Main.Member.P2)
        {
            if (Main.P2.skin.Head_Blend.action) enableAfterHeadBlend = true;
        }
        else if (Main.P1.skin.Head_Blend.action)
        {
            enableAfterHeadBlend = true;
        }
        for (int i = 1; i < 3; i++) menu.MenuItems[i].Enabled = false;
        for (int j = 1; j < 3; j++) if (enableAfterHeadBlend) menu.MenuItems[j].Enabled = true;
    }

    private static void OnItemSelect(UIMenu sender, UIMenuItem item, int index)
    {
        if (index == 0) HeadBlendSubMenu.InitHeadBlendSubMenu();
        if (index == 1) FaceFeatureSubMenu.InitFaceFeatureSubMenu();
        if (index == 2) HeadOverlayMenu.InitHeadOverlayMenu();
        if (index == 3) SpeechMenu.InitSpeakMenu();
    }

    private static void OnMenuClose(UIMenu sender)
    {
        menu.Visible = false;
        // 不刷新
    }
}


